from __future__ import annotations

from dataclasses import dataclass


@dataclass
class GantryStrength:
    member_stress_MPa: float
    utilization: float
    ok: bool
    note: str


def check_gantry_member(axial_kN: float, bending_kNm: float, area_mm2: float, section_modulus_mm3: float, design_strength_MPa: float = 215.0) -> GantryStrength:
    sigma = axial_kN * 1e3 / max(1.0, area_mm2) + abs(bending_kNm) * 1e6 / max(1.0, section_modulus_mm3)
    u = sigma / max(1e-6, design_strength_MPa)
    return GantryStrength(member_stress_MPa=sigma, utilization=u, ok=u <= 1.0, note="跨越架杆件强度")


@dataclass
class GantryStability:
    slenderness: float
    ok: bool
    note: str


def check_gantry_stability(effective_length_mm: float, radius_gyration_mm: float, limit: float = 180.0) -> GantryStability:
    slenderness = effective_length_mm / max(1e-6, radius_gyration_mm)
    return GantryStability(slenderness=slenderness, ok=slenderness <= limit, note="长细比限值验算")


